home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / ASM-SPAR.{_6 / AUDIOIO.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  18KB  |  519 lines

  1. /*
  2.  * include/asm-sparc/audioio.h
  3.  *
  4.  * Sparc Audio Midlayer
  5.  * Copyright (C) 1996 Thomas K. Dyas (tdyas@noc.rutgers.edu)
  6.  */
  7.  
  8. #ifndef _AUDIOIO_H_
  9. #define _AUDIOIO_H_
  10.  
  11. /*
  12.  *    SunOS/Solaris /dev/audio interface
  13.  */
  14.  
  15. #if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2)
  16. #include <linux/types.h>
  17. #include <linux/time.h>
  18. #include <linux/ioctl.h>
  19. #endif
  20.  
  21. /*
  22.  * This structure contains state information for audio device IO streams.
  23.  */
  24. typedef struct audio_prinfo {
  25.     /*
  26.      * The following values describe the audio data encoding.
  27.      */
  28.     unsigned int sample_rate;    /* samples per second */
  29.     unsigned int channels;    /* number of interleaved channels */
  30.     unsigned int precision;    /* bit-width of each sample */
  31.     unsigned int encoding;    /* data encoding method */
  32.  
  33.     /*
  34.      * The following values control audio device configuration
  35.      */
  36.     unsigned int gain;        /* gain level: 0 - 255 */
  37.     unsigned int port;        /* selected I/O port (see below) */
  38.     unsigned int avail_ports;    /* available I/O ports (see below) */
  39.     unsigned int _xxx[2];        /* Reserved for future use */
  40.  
  41.     unsigned int buffer_size;    /* I/O buffer size */
  42.  
  43.     /*
  44.      * The following values describe driver state
  45.      */
  46.     unsigned int samples;        /* number of samples converted */
  47.     unsigned int eof;        /* End Of File counter (play only) */
  48.  
  49.     unsigned char    pause;        /* non-zero for pause, zero to resume */
  50.     unsigned char    error;        /* non-zero if overflow/underflow */
  51.     unsigned char    waiting;    /* non-zero if a process wants access */
  52.     unsigned char balance;    /* stereo channel balance */
  53.  
  54.     unsigned short minordev;
  55.  
  56.     /*
  57.      * The following values are read-only state flags
  58.      */
  59.     unsigned char open;        /* non-zero if open access permitted */
  60.     unsigned char active;        /* non-zero if I/O is active */
  61. } audio_prinfo_t;
  62.  
  63.  
  64. /*
  65.  * This structure describes the current state of the audio device.
  66.  */
  67. typedef struct audio_info {
  68.     /*
  69.      * Per-stream information
  70.      */
  71.     audio_prinfo_t play;    /* output status information */
  72.     audio_prinfo_t record;    /* input status information */
  73.  
  74.     /*
  75.      * Per-unit/channel information
  76.      */
  77.     unsigned int monitor_gain;    /* input to output mix: 0 - 255 */
  78.     unsigned char output_muted;    /* non-zero if output is muted */
  79.     unsigned char _xxx[3];    /* Reserved for future use */
  80.     unsigned int _yyy[3];        /* Reserved for future use */
  81. } audio_info_t;
  82.  
  83.  
  84. /*
  85.  * Audio encoding types
  86.  */
  87. #define    AUDIO_ENCODING_NONE    (0)    /* no encoding assigned      */
  88. #define    AUDIO_ENCODING_ULAW    (1)    /* u-law encoding      */
  89. #define    AUDIO_ENCODING_ALAW    (2)    /* A-law encoding      */
  90. #define    AUDIO_ENCODING_LINEAR    (3)    /* Linear PCM encoding      */
  91. #define AUDIO_ENCODING_FLOAT    (4)     /* IEEE float (-1. <-> +1.) */
  92. #define    AUDIO_ENCODING_DVI    (104)    /* DVI ADPCM          */
  93. #define    AUDIO_ENCODING_LINEAR8    (105)    /* 8 bit UNSIGNED      */
  94. #define    AUDIO_ENCODING_LINEARLE    (106)    /* Linear PCM LE encoding */
  95.  
  96. /*
  97.  * These ranges apply to record, play, and monitor gain values
  98.  */
  99. #define    AUDIO_MIN_GAIN    (0)    /* minimum gain value */
  100. #define    AUDIO_MAX_GAIN    (255)    /* maximum gain value */
  101.  
  102. /*
  103.  * These values apply to the balance field to adjust channel gain values
  104.  */
  105. #define    AUDIO_LEFT_BALANCE    (0)    /* left channel only    */
  106. #define    AUDIO_MID_BALANCE    (32)    /* equal left/right channel */
  107. #define    AUDIO_RIGHT_BALANCE    (64)    /* right channel only    */
  108. #define    AUDIO_BALANCE_SHIFT    (3)
  109.  
  110. /*
  111.  * Generic minimum/maximum limits for number of channels, both modes
  112.  */
  113. #define    AUDIO_MIN_PLAY_CHANNELS    (1)
  114. #define    AUDIO_MAX_PLAY_CHANNELS    (4)
  115. #define    AUDIO_MIN_REC_CHANNELS    (1)
  116. #define    AUDIO_MAX_REC_CHANNELS    (4)
  117.  
  118. /*
  119.  * Generic minimum/maximum limits for sample precision
  120.  */
  121. #define    AUDIO_MIN_PLAY_PRECISION    (8)
  122. #define    AUDIO_MAX_PLAY_PRECISION    (32)
  123. #define    AUDIO_MIN_REC_PRECISION        (8)
  124. #define    AUDIO_MAX_REC_PRECISION        (32)
  125.  
  126. /*
  127.  * Define some convenient names for typical audio ports
  128.  */
  129. /*
  130.  * output ports (several may be enabled simultaneously)
  131.  */
  132. #define    AUDIO_SPEAKER        0x01    /* output to built-in speaker */
  133. #define    AUDIO_HEADPHONE        0x02    /* output to headphone jack */
  134. #define    AUDIO_LINE_OUT        0x04    /* output to line out     */
  135.  
  136. /*
  137.  * input ports (usually only one at a time)
  138.  */
  139. #define    AUDIO_MICROPHONE    0x01    /* input from microphone */
  140. #define    AUDIO_LINE_IN        0x02    /* input from line in     */
  141. #define    AUDIO_CD        0x04    /* input from on-board CD inputs */
  142. #define    AUDIO_INTERNAL_CD_IN    AUDIO_CD    /* input from internal CDROM */
  143. #define AUDIO_ANALOG_LOOPBACK   0x40    /* input from output */
  144.  
  145.  
  146. /*
  147.  * This macro initializes an audio_info structure to 'harmless' values.
  148.  * Note that (~0) might not be a harmless value for a flag that was
  149.  * a signed int.
  150.  */
  151. #define    AUDIO_INITINFO(i)    {                    \
  152.     unsigned int    *__x__;                        \
  153.     for (__x__ = (unsigned int *)(i);                \
  154.         (char *) __x__ < (((char *)(i)) + sizeof (audio_info_t));    \
  155.         *__x__++ = ~0);                        \
  156. }
  157.  
  158. /*
  159.  * These allow testing for what the user wants to set 
  160.  */
  161. #define AUD_INITVALUE   (~0)
  162. #define Modify(X)       ((unsigned int)(X) != AUD_INITVALUE)
  163. #define Modifys(X)      ((X) != (unsigned short)AUD_INITVALUE)
  164. #define Modifyc(X)      ((X) != (unsigned char)AUD_INITVALUE)
  165.  
  166. /*
  167.  * Parameter for the AUDIO_GETDEV ioctl to determine current
  168.  * audio devices.
  169.  */
  170. #define    MAX_AUDIO_DEV_LEN    (16)
  171. typedef struct audio_device {
  172.     char name[MAX_AUDIO_DEV_LEN];
  173.     char version[MAX_AUDIO_DEV_LEN];
  174.     char config[MAX_AUDIO_DEV_LEN];
  175. } audio_device_t;
  176.  
  177.  
  178. /*
  179.  * Ioctl calls for the audio device.
  180.  */
  181.  
  182. /*
  183.  * AUDIO_GETINFO retrieves the current state of the audio device.
  184.  *
  185.  * AUDIO_SETINFO copies all fields of the audio_info structure whose
  186.  * values are not set to the initialized value (-1) to the device state.
  187.  * It performs an implicit AUDIO_GETINFO to return the new state of the
  188.  * device.  Note that the record.samples and play.samples fields are set
  189.  * to the last value before the AUDIO_SETINFO took effect.  This allows
  190.  * an application to reset the counters while atomically retrieving the
  191.  * last value.
  192.  *
  193.  * AUDIO_DRAIN suspends the calling process until the write buffers are
  194.  * empty.
  195.  *
  196.  * AUDIO_GETDEV returns a structure of type audio_device_t which contains
  197.  * three strings.  The string "name" is a short identifying string (for
  198.  * example, the SBus Fcode name string), the string "version" identifies
  199.  * the current version of the device, and the "config" string identifies
  200.  * the specific configuration of the audio stream.  All fields are
  201.  * device-dependent -- see the device specific manual pages for details.
  202.  *
  203.  * AUDIO_GETDEV_SUNOS returns a number which is an audio device defined 
  204.  * herein (making it not too portable)
  205.  *
  206.  * AUDIO_FLUSH stops all playback and recording, clears all queued buffers, 
  207.  * resets error counters, and restarts recording and playback as appropriate
  208.  * for the current sampling mode.
  209.  */
  210. #define    AUDIO_GETINFO    _IOR('A', 1, audio_info_t)
  211. #define    AUDIO_SETINFO    _IOWR('A', 2, audio_info_t)
  212. #define    AUDIO_DRAIN    _IO('A', 3)
  213. #define    AUDIO_GETDEV    _IOR('A', 4, audio_device_t)
  214. #define    AUDIO_GETDEV_SUNOS    _IOR('A', 4, int)
  215. #define AUDIO_FLUSH     _IO('A', 5)
  216.  
  217. /* Define possible audio hardware configurations for 
  218.  * old SunOS-style AUDIO_GETDEV ioctl */
  219. #define AUDIO_DEV_UNKNOWN       (0)     /* not defined */
  220. #define AUDIO_DEV_AMD           (1)     /* audioamd device */
  221. #define AUDIO_DEV_SPEAKERBOX    (2)     /* dbri device with speakerbox */
  222. #define AUDIO_DEV_CODEC         (3)     /* dbri device (internal speaker) */
  223. #define AUDIO_DEV_CS4231        (5)     /* cs4231 device */
  224.  
  225. /*
  226.  * The following ioctl sets the audio device into an internal loopback mode,
  227.  * if the hardware supports this.  The argument is TRUE to set loopback,
  228.  * FALSE to reset to normal operation.  If the hardware does not support
  229.  * internal loopback, the ioctl should fail with EINVAL.
  230.  * Causes ADC data to be digitally mixed in and sent to the DAC.
  231.  */
  232. #define    AUDIO_DIAG_LOOPBACK    _IOW('A', 101, int)
  233.  
  234. /*
  235.  *    Linux kernel internal implementation.
  236.  */
  237.  
  238. #ifdef __KERNEL__
  239.  
  240. #include <linux/types.h>
  241. #include <linux/fs.h>
  242. #include <linux/tqueue.h>
  243. #include <linux/wait.h>
  244.  
  245. #define    SDF_OPEN_WRITE    0x00000001
  246. #define    SDF_OPEN_READ    0x00000002
  247.  
  248. struct sparcaudio_ringbuffer
  249. {
  250.   __u8 *rb_start, *rb_end;        /* start, end of this memory buffer */
  251.   __u8 *rb_in, *rb_out;            /* input, output pointers */
  252.  
  253.   int rb_fragsize;            /* size of an audio frag */
  254.   int rb_numfrags;            /* number of frags */
  255.  
  256.   int rb_count, rb_hiwat, rb_lowat;    /* bytes in use, hi/lo wat points */
  257.  
  258.   int rb_bufsize;            /* total size of buffer */
  259. };
  260.  
  261. struct sparcaudio_driver
  262. {
  263.     const char * name;
  264.     struct sparcaudio_operations *ops;
  265.     void *private;
  266.     unsigned long flags;
  267.         struct strevent *sd_siglist;
  268.         /* duplex: 0=simplex, 1=duplex, 2=loop */
  269.         int sd_sigflags, duplex;
  270.  
  271.         /* Which audio device are we? */
  272.         int index; 
  273.  
  274.         /* This device */
  275.         struct linux_sbus_device *dev;
  276.  
  277.     /* Processes blocked on open() sit here. */
  278.     struct wait_queue *open_wait;
  279.  
  280.     /* Task queue for this driver's bottom half. */
  281.     struct tq_struct tqueue;
  282.  
  283.         /* Start of ring buffer support */
  284.         __u8 *input_buffer, *output_buffer;
  285.  
  286.     /* Support for a circular queue of output buffers. */
  287.     __u8 **output_buffers;
  288.     size_t *output_sizes, output_size, output_buffer_size;
  289.     int num_output_buffers, output_front, output_rear, output_offset;
  290.     int output_count, output_active, playing_count, output_eof;
  291.     struct wait_queue *output_write_wait, *output_drain_wait;
  292.         char *output_notify;
  293.  
  294.         /* Support for a circular queue of input buffers. */
  295.         __u8 **input_buffers;
  296.     size_t *input_sizes, input_size, input_buffer_size;
  297.         int num_input_buffers, input_front, input_rear, input_offset;
  298.         int input_count, input_active, recording_count;
  299.         struct wait_queue *input_read_wait;
  300.  
  301.         /* Hack to make it look like we support variable size buffers. */
  302.         int buffer_size;
  303. };
  304.  
  305. struct sparcaudio_operations
  306. {
  307.     int (*open)(struct inode *, struct file *, struct sparcaudio_driver *);
  308.     void (*release)(struct inode *, struct file *, struct sparcaudio_driver *);
  309.     int (*ioctl)(struct inode *, struct file *, unsigned int, unsigned long,
  310.              struct sparcaudio_driver *);
  311.  
  312.     /* Ask driver to begin playing a buffer. */
  313.     void (*start_output)(struct sparcaudio_driver *, __u8 *, unsigned long);
  314.  
  315.     /* Ask driver to stop playing a buffer. */
  316.     void (*stop_output)(struct sparcaudio_driver *);
  317.  
  318.     /* Ask driver to begin recording into a buffer. */
  319.     void (*start_input)(struct sparcaudio_driver *, __u8 *, unsigned long);
  320.  
  321.     /* Ask driver to stop recording. */
  322.     void (*stop_input)(struct sparcaudio_driver *);
  323.  
  324.     /* Return driver name/version to caller. (/dev/audio specific) */
  325.     void (*sunaudio_getdev)(struct sparcaudio_driver *, audio_device_t *);
  326.  
  327.         /* Get and set the output volume. (0-255) */
  328.         int (*set_output_volume)(struct sparcaudio_driver *, int);
  329.         int (*get_output_volume)(struct sparcaudio_driver *);
  330.  
  331.         /* Get and set the input volume. (0-255) */
  332.         int (*set_input_volume)(struct sparcaudio_driver *, int);
  333.         int (*get_input_volume)(struct sparcaudio_driver *);
  334.  
  335.         /* Get and set the monitor volume. (0-255) */
  336.         int (*set_monitor_volume)(struct sparcaudio_driver *, int);
  337.         int (*get_monitor_volume)(struct sparcaudio_driver *);
  338.  
  339.         /* Get and set the output balance. (0-64) */
  340.         int (*set_output_balance)(struct sparcaudio_driver *, int);
  341.         int (*get_output_balance)(struct sparcaudio_driver *);
  342.  
  343.         /* Get and set the input balance. (0-64) */
  344.         int (*set_input_balance)(struct sparcaudio_driver *, int);
  345.         int (*get_input_balance)(struct sparcaudio_driver *);
  346.  
  347.         /* Get and set the output channels. (1-4) */
  348.         int (*set_output_channels)(struct sparcaudio_driver *, int);
  349.         int (*get_output_channels)(struct sparcaudio_driver *);
  350.  
  351.         /* Get and set the input channels. (1-4) */
  352.         int (*set_input_channels)(struct sparcaudio_driver *, int);
  353.         int (*get_input_channels)(struct sparcaudio_driver *);
  354.  
  355.         /* Get and set the output precision. (8-32) */
  356.         int (*set_output_precision)(struct sparcaudio_driver *, int);
  357.         int (*get_output_precision)(struct sparcaudio_driver *);
  358.  
  359.         /* Get and set the input precision. (8-32) */
  360.         int (*set_input_precision)(struct sparcaudio_driver *, int);
  361.         int (*get_input_precision)(struct sparcaudio_driver *);
  362.  
  363.         /* Get and set the output port. () */
  364.         int (*set_output_port)(struct sparcaudio_driver *, int);
  365.         int (*get_output_port)(struct sparcaudio_driver *);
  366.  
  367.         /* Get and set the input port. () */
  368.         int (*set_input_port)(struct sparcaudio_driver *, int);
  369.         int (*get_input_port)(struct sparcaudio_driver *);
  370.  
  371.         /* Get and set the output encoding. () */
  372.         int (*set_output_encoding)(struct sparcaudio_driver *, int);
  373.         int (*get_output_encoding)(struct sparcaudio_driver *);
  374.  
  375.         /* Get and set the input encoding. () */
  376.         int (*set_input_encoding)(struct sparcaudio_driver *, int);
  377.         int (*get_input_encoding)(struct sparcaudio_driver *);
  378.  
  379.         /* Get and set the output rate. () */
  380.         int (*set_output_rate)(struct sparcaudio_driver *, int);
  381.         int (*get_output_rate)(struct sparcaudio_driver *);
  382.  
  383.         /* Get and set the input rate. () */
  384.         int (*set_input_rate)(struct sparcaudio_driver *, int);
  385.         int (*get_input_rate)(struct sparcaudio_driver *);
  386.  
  387.     /* Return driver number to caller. (SunOS /dev/audio specific) */
  388.     int (*sunaudio_getdev_sunos)(struct sparcaudio_driver *);
  389.  
  390.         /* Get available ports */
  391.         int (*get_output_ports)(struct sparcaudio_driver *);
  392.         int (*get_input_ports)(struct sparcaudio_driver *);
  393.  
  394.         /* Get and set output mute */
  395.         int (*set_output_muted)(struct sparcaudio_driver *, int);
  396.         int (*get_output_muted)(struct sparcaudio_driver *);
  397.  
  398.         /* Get and set output pause */
  399.         int (*set_output_pause)(struct sparcaudio_driver *, int);
  400.         int (*get_output_pause)(struct sparcaudio_driver *);
  401.  
  402.         /* Get and set input pause */
  403.         int (*set_input_pause)(struct sparcaudio_driver *, int);
  404.         int (*get_input_pause)(struct sparcaudio_driver *);
  405.  
  406.         /* Get and set output samples */
  407.         int (*set_output_samples)(struct sparcaudio_driver *, int);
  408.         int (*get_output_samples)(struct sparcaudio_driver *);
  409.  
  410.         /* Get and set input samples */
  411.         int (*set_input_samples)(struct sparcaudio_driver *, int);
  412.         int (*get_input_samples)(struct sparcaudio_driver *);
  413.  
  414.         /* Get and set output error */
  415.         int (*set_output_error)(struct sparcaudio_driver *, int);
  416.         int (*get_output_error)(struct sparcaudio_driver *);
  417.  
  418.         /* Get and set input error */
  419.         int (*set_input_error)(struct sparcaudio_driver *, int);
  420.         int (*get_input_error)(struct sparcaudio_driver *);
  421.  
  422.         /* Get supported encodings */
  423.         int (*get_formats)(struct sparcaudio_driver *);
  424. };
  425.  
  426. extern int register_sparcaudio_driver(struct sparcaudio_driver *, int);
  427. extern int unregister_sparcaudio_driver(struct sparcaudio_driver *, int);
  428. extern void sparcaudio_output_done(struct sparcaudio_driver *, int);
  429. extern void sparcaudio_input_done(struct sparcaudio_driver *, int);
  430. extern int sparcaudio_init(void);
  431. extern int amd7930_init(void);
  432. extern int cs4231_init(void);
  433.  
  434. #endif
  435.  
  436. /* Mixer helper ioctls */
  437. #define right(a) (((a >> 8) & 0xff) % 101)
  438. #define left(a) ((a & 0xff) % 101)
  439.  
  440. /* Macros to convert between mixer stereo volumes and gain (mono) */
  441. #define s_to_m(a) ((((left(a) + right(a)) * 255) / 200) % 256)
  442. #define m_to_s(a) ((a * 100 / 255) + ((a * 100 / 255) << 8))
  443.  
  444. /* convert mixer stereo volume to balance */
  445. #define s_to_b(a) (s_to_g(a) == 0) ? 32 : ((left(a) * AUDIO_RIGHT_BALANCE / (left(a) + right(a))))
  446.  
  447. /* convert mixer stereo volume to audio gain */
  448. #define s_to_g(a) ((((right(a) + left(a)) * 255) / 200) % 256)
  449.  
  450. /* convert gain a and balance b to mixer volume */
  451. #define b_to_s(a,b) (((((b * a * 200) / (AUDIO_RIGHT_BALANCE * 255)) % 100) << 8) + ((((AUDIO_RIGHT_BALANCE - b) * a * 200) / (AUDIO_RIGHT_BALANCE * 255)) % 100))
  452.  
  453. /* Device minor numbers */
  454.  
  455. #define SPARCAUDIO_MIXER_MINOR 0
  456. /* No sequencer (1) */
  457. /* No midi (2) */
  458. #define SPARCAUDIO_DSP_MINOR   3
  459. #define SPARCAUDIO_AUDIO_MINOR 4
  460. #define SPARCAUDIO_DSP16_MINOR 5
  461. #define SPARCAUDIO_STATUS_MINOR 6
  462. #define SPARCAUDIO_AUDIOCTL_MINOR 7
  463. /* No sequencer l2 (8) */
  464. /* No sound processor (9) */
  465.  
  466. /* allocate 2^SPARCAUDIO_DEVICE_SHIFT minors per audio device */
  467. #define SPARCAUDIO_DEVICE_SHIFT 4
  468.  
  469. /* With the coming of dummy devices this should perhaps be as high as 5? */
  470. #define SPARCAUDIO_MAX_DEVICES 3
  471.  
  472. /* Streams crap for realaudio */
  473.  
  474. typedef
  475. struct strevent {
  476.     struct strevent *se_next;   /* next event for this stream or NULL*/
  477.     struct strevent *se_prev;   /* previous event for this stream or last
  478.                                  * event if this is the first one*/
  479.     pid_t se_pid;               /* process to be signaled */
  480.     short se_evs;               /* events wanted */
  481. } strevent_t;
  482.  
  483. typedef
  484. struct stdata
  485. {
  486.         struct stdata    *sd_next ;     /* all stdatas are linked together */
  487.         struct stdata    *sd_prev ;
  488.         struct strevent   *sd_siglist;  /* processes to be sent SIGPOLL */
  489.         int  sd_sigflags;               /* logical OR of all siglist events */
  490. } stdata_t;
  491.  
  492. #define I_NREAD _IOR('S',01, int)
  493. #define I_NREAD_SOLARIS (('S'<<8)|1)
  494.  
  495. #define I_FLUSH _IO('S',05)
  496. #define I_FLUSH_SOLARIS (('S'<<8)|5)
  497. #define FLUSHR  1                       /* flush read queue */
  498. #define FLUSHW  2                       /* flush write queue */
  499. #define FLUSHRW 3                       /* flush both queues */
  500.  
  501. #define I_SETSIG _IO('S',011)
  502. #define I_SETSIG_SOLARIS (('S'<<8)|11)
  503. #define S_INPUT         0x01
  504. #define S_HIPRI         0x02           
  505. #define S_OUTPUT        0x04           
  506. #define S_MSG           0x08           
  507. #define S_ERROR         0x0010         
  508. #define S_HANGUP        0x0020         
  509. #define S_RDNORM        0x0040         
  510. #define S_WRNORM        S_OUTPUT
  511. #define S_RDBAND        0x0080         
  512. #define S_WRBAND        0x0100         
  513. #define S_BANDURG       0x0200         
  514. #define S_ALL           0x03FF
  515.  
  516. #define I_GETSIG _IOR('S',012,int)
  517. #define I_GETSIG_SOLARIS (('S'<<8)|12)
  518. #endif
  519.